package com.mytest.service;

import com.mytest.controller.HomeController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HomeService {

    private static final Logger logger = LoggerFactory.getLogger(HomeService.class);
    @Autowired
    MyService myService;

    public synchronized void method(String string){

        logger.info("home service method");
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if ("true".equals(string)){
            myService.method(string);
        }
    }

    public synchronized void method1(String string){

        logger.info("service method1");
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if ("true".equals(string)){
            method2(string);
        }
    }

    public synchronized void method2(String string){

        logger.info("service method2");
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if ("false".equals(string)){
            method1(string);
        }
    }
}
